package com.hckj.jianzhijia;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.View;

import com.hckj.jianzhijia.model.CompanyUser;
import com.hckj.jianzhijia.utils.MyActivityManager;
import com.rey.material.app.Dialog;
import com.rey.material.app.DialogFragment;
import com.rey.material.app.SimpleDialog;


abstract public class BaseActivity extends FragmentActivity {

    protected View listEmptyView;
    protected JianzhijiaApplacation jianzhijiaApplacation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        MyActivityManager.getInstance().addActivity(this);
        jianzhijiaApplacation = (JianzhijiaApplacation) getApplication();

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MyActivityManager.getInstance().finishActivity(this);
    }

    /**
     * 获取加载失败的View
     * @return
     */
    protected View getLoadNothingView(){
        listEmptyView = View.inflate(this, R.layout.new_activity_load_nothing_layout,null);
        return listEmptyView;
    }

    protected interface DialogAction {
        void positiveAction();
        void negativeAction();
    }

    protected void showMaterialDialog(String content, String title, final DialogAction dialogAction) {

        Dialog.Builder builder = null;
        builder = new SimpleDialog.Builder(R.style.SimpleDialogLight) {
            @Override
            public void onPositiveActionClicked(DialogFragment fragment) {
                fragment.dismiss();
                dialogAction.positiveAction();
                super.onPositiveActionClicked(fragment);
            }

            @Override
            public void onNegativeActionClicked(DialogFragment fragment) {
                fragment.dismiss();
                dialogAction.negativeAction();
                super.onNegativeActionClicked(fragment);
            }
        };

        ((SimpleDialog.Builder) builder).message(content)
                    .positiveAction("确认")
                    .negativeAction("取消").title(title);
        DialogFragment fragment = DialogFragment.newInstance(builder);
        fragment.setCancelable(false);
        fragment.show(getSupportFragmentManager(), null);
    }
}
